package com.boang.daemon;

import java.io.IOException;

/*
  @author: 13813
  @date: 2024/11/28 11:38
*/
public class DaemonDemo extends Thread {

    @Override
    public void run() {
        for (int i = 0; i < 10000; i++) {
            try {
                Thread.sleep(1000000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName() + ":" + i);
        }
    }

    //守护线程
    public static void main(String[] args) throws IOException {
        DaemonDemo daemonDemo = new DaemonDemo();
        daemonDemo.setDaemon(true); //守护线程（后台线程），当线程都是守护线程时，JVM退出
        daemonDemo.start();

        System.in.read();
    }
}
